﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using AspNetCs.Model;
using AspNetCs.IDAL;

namespace AspNetCs.SQLServerDAL
{
    public class AncestralHallItems_DAL:IAncestralHallItems
    {
        /// <summary>
        /// 添加宗祠版块
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(AncestralHallItems_Model model)
        {
            int count=0;
            db.ParameterArry[] paras=new db.ParameterArry[8];

            paras[0].dbType=SqlDbType.Int;
            paras[0].parName="@AncestralHallId";
            paras[0].objValue=model.AncestralHallId;

            paras[1].dbType=SqlDbType.Text;
            paras[1].parName="@ItemName";
            paras[1].objValue=model.ItemName;

            paras[2].dbType=SqlDbType.Text;
            paras[2].parName="@ItemLogo";
            paras[2].objValue=model.ItemLogo;

            paras[3].dbType=SqlDbType.Text;
            paras[3].parName="@Introduction";
            paras[3].objValue=model.Introduction;

            paras[4].dbType=SqlDbType.DateTime;
            paras[4].parName="@CreateTime";
            paras[4].objValue=model.CreateTime;

            paras[5].dbType=SqlDbType.Int;
            paras[5].parName="@IsCheck";
            paras[5].objValue=model.IsCheck;

            paras[6].dbType=SqlDbType.Int;
            paras[6].parName="@IsDel";
            paras[6].objValue=model.IsDel;

            paras[7].dbType = SqlDbType.Int;
            paras[7].parName = "@IsSys";
            paras[7].objValue = model.IsSys;

            string cmdText = "insert into AncestralHallItems values ({0},{1},{2},{3},{4},{5},{6},{7})";
            cmdText = string.Format(cmdText,paras[0].parName,paras[1].parName,paras[2].parName,paras[3].parName,paras[4].parName,paras[5].parName,paras[6].parName,paras[7].parName);
            db dbclass = new db();
            count = dbclass.ExcSql(cmdText,paras);
            return count;
        }

        /// <summary>
        /// 修改宗祠版块
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(AncestralHallItems_Model model)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[8];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = model.AncestralHallId;

            paras[1].dbType = SqlDbType.Text;
            paras[1].parName = "@ItemName";
            paras[1].objValue = model.ItemName;

            paras[2].dbType = SqlDbType.Text;
            paras[2].parName = "@ItemLogo";
            paras[2].objValue = model.ItemLogo;

            paras[3].dbType = SqlDbType.Text;
            paras[3].parName = "@Introduction";
            paras[3].objValue = model.Introduction;

            paras[4].dbType = SqlDbType.DateTime;
            paras[4].parName = "@CreateTime";
            paras[4].objValue = model.CreateTime;

            paras[5].dbType = SqlDbType.Int;
            paras[5].parName = "@IsCheck";
            paras[5].objValue = model.IsCheck;

            paras[6].dbType = SqlDbType.Int;
            paras[6].parName = "@IsDel";
            paras[6].objValue = model.IsDel;

            paras[7].dbType = SqlDbType.Int;
            paras[7].parName = "@Id";
            paras[7].objValue = model.Id;

            string cmdText = "update AncestralHallItems set AncestralHallId={0},ItemName={1},ItemLogo={2},Introduction={3},CreateTime={4},IsCheck={5},IsDel={6} where Id={7}";
            cmdText = string.Format(cmdText, paras[0].parName, paras[1].parName, paras[2].parName, paras[3].parName, paras[4].parName, paras[5].parName, paras[6].parName, paras[7].parName);
            db dbclass = new db();
            count = dbclass.ExcSql(cmdText, paras);
            return count;
        }

        /// <summary>
        /// 删除宗祠版块(物理删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(int id)
        {
            int count = 0;
            db.ParameterArry[] paras=new db.ParameterArry[1];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = id;

            db dbclass = new db();

            string cmdText = "delete from AncestralHallItems where AncestralHallId=@AncestralHallId";
            count = dbclass.ExcSql(cmdText,paras);
            return count;
        }

        /// <summary>
        /// 删除宗祠版块(逻辑删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Hidden(int id)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[1];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = id;

            db dbclass = new db();

            string cmdText = "update  AncestralHallItems set IsDel=1 where AncestralHallId=@AncestralHallId";
            count = dbclass.ExcSql(cmdText, paras);
            return count;
        }

        /// <summary>
        /// 删除宗祠版块通过编号(物理删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteById(int id)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[1];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@Id";
            paras[0].objValue = id;

            db dbclass = new db();

            string cmdText = "delete from AncestralHallItems where Id=@Id";
            count = dbclass.ExcSql(cmdText, paras);
            return count;
        }

        /// <summary>
        /// 删除宗祠版块通过编号(逻辑删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int HiddenById(int id)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[1];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@Id";
            paras[0].objValue = id;

            db dbclass = new db();

            string cmdText = "update  AncestralHallItems set IsDel=1 where Id=@Id";
            count = dbclass.ExcSql(cmdText, paras);
            return count;
        }


        /// <summary>
        /// 通过宗祠编号查询宗祠版块
        /// </summary>
        /// <param name="CreateId">宗祠编号</param>
        /// <param name="RequeryItems">查询的字段</param>
        /// <param name="IsDel">是否查询的被删除的信息 0:没有删除的 1:删除了的 2:所有的</param>
        /// <returns></returns>
        public DataTable getAncestralHallItemsByAncestralHallId(int id, string RequeryItems, int IsDel)
        {
            DataTable dataTable = new DataTable();
            db.ParameterArry[] paras = new db.ParameterArry[2];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = id;

            paras[1].dbType = SqlDbType.Int;
            paras[1].parName = "@IsDel";
            paras[1].objValue = IsDel;

            string cmdText = "select {0} from AncestralHallItems where AncestralHallId=@AncestralHallId and IsDel=@IsDel order by IsSys desc ";
            cmdText = string.Format(cmdText,RequeryItems);

            db dbclass = new db();

            dataTable = dbclass.GetSql_DataTable(cmdText,paras);
            return dataTable;
        }


        public DataTable GetDataTable(string filter)
        {
            DataTable dataTable = new DataTable();
            string cmdText = "select *from AncestralHallItems where {0}";
            cmdText = string.Format(cmdText,filter);
            db dbclass = new db();
            dataTable = dbclass.GetSql_DataTable(cmdText);
            return dataTable;
        }
    }
}
